/*
 * Copyright (C) 2011 Nicola Bonzanni
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nl.vu.few.ibivu.jlemon;

import nl.vu.few.ibivu.jlemon.concepts.Arc;
import nl.vu.few.ibivu.jlemon.concepts.Graph;
import nl.vu.few.ibivu.jlemon.concepts.Node;


public class IncomingArcIterator<A extends Arc & Comparable<A>> extends AbstractIterator<A> {

	private Graph<?,A> graph;

	/**
	 * An iterator initialized with this constructor will behave as a
	 * standard java iterator, i.e. the state of the iterator before calling
	 * next() is undefined and the first call to next() will return the
	 * <b>first</b> incoming arc to the given node (if any). If you desire
	 * an iterator that represent the first incoming arc and such that the
	 * first call to next() returns the <b>second</b> incoming arc, you
	 * should use <tt>IncomingArcIterator(graph.firstIn(this))</tt> instead.
	 * 
	 * @param node
	 *            a node belonging to the given graph
	 * @param graph TODO
	 * @see #IncomingArcIterator(Arc)
	 * @see Graph#firstIn(Node)
	 */
	public <N extends Node & Comparable<N>> IncomingArcIterator(Graph<N,A> graph, N node) {
		super(null, graph.firstIn(node));
		this.graph = graph;
	}

	/**
	 * An iterator initialized with this constructor represent the given
	 * incoming arc until the next() function is called. The first call to
	 * next() will return the incoming arc next to the given one, and will
	 * set the iterator to represent the returned arc accordingly.
	 * 
	 * @param arc
	 *            an arc belonging to the given graph
	 * @param graph TODO
	 * @see #IncomingArcIterator(Node)
	 */
	public IncomingArcIterator(Graph<?,A> graph, A arc) {
		super(arc, graph.nextIn(arc));
		this.graph = graph;
	}

	@Override
	protected A computeNext() {
		return graph.nextIn(current);
	}

}